//
//  FDMPushSectionOneCollectionViewCell.m
//  Entertainment
//
//  Created by dllo on 16/4/20.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMPushSectionOneCollectionViewCell.h"
#import "FDMPushListenNewsCollectionViewCell.h"
#import "FDMPushFindNewsModel.h"

@interface FDMPushSectionOneCollectionViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) FDMBaseCollectionView *collectionView;

@end
@implementation FDMPushSectionOneCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCollection];
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

- (void)setDataSourceModelArr:(NSMutableArray *)dataSourceModelArr {
    if (_dataSourceModelArr != dataSourceModelArr) {
        [_dataSourceModelArr release];
        _dataSourceModelArr = [dataSourceModelArr retain];
        [self.collectionView reloadData];
    }
    
    
}

- (void)createCollection {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((CONTENTVIEW_WIDTH - 50) / 4, CONTENTVIEW_HEIGHT - 20);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView = [[FDMBaseCollectionView alloc] initWithFrame:CGRectMake(0, 0, CONTENTVIEW_WIDTH, CONTENTVIEW_HEIGHT) collectionViewLayout:layout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.contentView addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor purpleColor];
    self.collectionView.pagingEnabled = YES;
    [self.collectionView registerClass:[FDMPushListenNewsCollectionViewCell class] forCellWithReuseIdentifier:@"FDMPushListenNewsCollectionViewCell"];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataSourceModelArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    FDMPushListenNewsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FDMPushListenNewsCollectionViewCell" forIndexPath:indexPath];
    FDMPushFindNewsModel *model = self.dataSourceModelArr[indexPath.row];
    cell.model = model;
    cell.backgroundColor = [UIColor yellowColor];
    return cell;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
